<h3>Usage Reports</h3>
<?php 

include ("../_vars.php");

//I. Number of users
echo "<h4>Total registered users:</h4>";
$n_users = mysql_num_rows(mysql_query("SELECT * FROM `users`"));

echo $n_users;

//II. Average ratings for providers
echo "<hr/>";
// 1. get providers
$results = mysql_query("SELECT * FROM `adds`");
$provider_ids = array();
$n_rows=0;
while ($row = mysql_fetch_assoc($results) ) {
  $provider_ids[$n_rows] = array( "id" => $row["id"], "active" => $row["active"], "name" =>$row["name"]);
  $n_rows++;
}

// 2. get average for each
echo "<h4>Average ratings for providers:</h4>";
echo "<hr/>";
for ($i=0;$i<$n_rows;$i++) {
  $id = $provider_ids[$i]["id"];
  $name = $provider_ids[$i]["name"];
  $active = $provider_ids[$i]["active"];
  echo $id."  ".$name."    ".$active."<br/>";
  $result = mysql_query("SELECT * FROM `rating` WHERE `add_id`=$id");
//  $n_rows = mysql_num_rows($result);
  $sum = 0;
  while ($row = mysql_fetch_assoc($result) ) {
    echo $row["user_id"]." ".$row["options"]."<br/>";
    $sum += $row["options"];
  }
  $avg = $sum;// / $n_rows;
  echo "Average: ".$avg."<hr/>";
}
?>


